﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 观察者模式
{
    //显示当前天气的公告牌
    class CurrentConditionsDisplay : Observer,DisplayElement
    {
        private WeatherData _weatherData;

        private float temperature;//温度
        private float humidity;//湿度
        private float pressure;//气压

        public CurrentConditionsDisplay(WeatherData weatherData)
        {
            _weatherData = weatherData;
            _weatherData.registerObserver(this);
        }

        public  void display()
        {
            Console.WriteLine("当前温度为：" + this.temperature + "℃");
            Console.WriteLine("当前湿度为：" + this.humidity);
            Console.WriteLine("当前气压为：" + this.pressure);
        }

        public override void update(string msg)
        {
            this.temperature = _weatherData.getTemperature();
            this.humidity = _weatherData.getHumidity();
            this.pressure = _weatherData.getPressure();
            display();
        }
    }
}
